package com.ma.logicThread;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

import com.ma.game.game_room_2;
import com.ma.logicHandler.gameLoginHandler;
import com.ma.logicHandler.gameStartHandler;
import com.ma.queue.BaseQueue;
import com.server.java.constants.CmdConstant;
import com.server.java.entity.MsgEntity;

import io.netty.channel.Channel;

public class HandleLoginRunnable extends AbstractCmdRunnable {

	public HandleLoginRunnable(BaseQueue<MsgEntity> INSTANCE) {
		super(INSTANCE);
//		logicMapInit();
	}

	@Override
	public void handleMsg(MsgEntity msgEntity) {
		System.out.println("2222222222222222222222");
		List<MsgEntity> commandList = new ArrayList<MsgEntity>();
		try {
			handlerMap.get(msgEntity.getCmdCode()).handleMsg(msgEntity, commandList, this);
		} catch (Exception e) {
			e.printStackTrace();
		}
		if (commandList != null && commandList.size() > 0) {
			for (MsgEntity tempMessage : commandList) {
				tempMessage.getChannel().writeAndFlush(tempMessage);
			}
		}
		commandList.clear();
		commandList = null;
	}

	@Override
	public void logicMapInit() {
		handlerMap.put(CmdConstant.login, new gameLoginHandler());
	}

	@Override
	public void run()  {
		for (;;) {
			super.run();
			try {
				TimeUnit.MILLISECONDS.sleep(50);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

	}

}
